package com.clubs.coding.Controller;

import com.clubs.coding.Service.AthLeaveService;
import com.clubs.coding.common.ApiRestResponse;
import com.clubs.coding.exception.ImoocMallException;
import com.clubs.coding.exception.ImoocMallExceptionEnum;
import com.clubs.coding.model.pojo.AthLeave;

import com.clubs.coding.model.pojo.MakeTime;
import com.clubs.coding.model.request.AthLeaveReq;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Date;
import java.util.List;
/**
 *
 前台请假控制器

 */
@Controller
@ResponseBody

public class AthLeaveController {
@Autowired
AthLeaveService athLeaveService;
//请假
@PostMapping("/record/goleave")
    public ApiRestResponse goleave(@RequestBody @Valid AthLeaveReq athLeaveReq){
    if (athLeaveReq==null) {
        throw new ImoocMallException(ImoocMallExceptionEnum.IS_LEAVE);
    }
    athLeaveReq.setCreateTime(new Date());
    athLeaveService.goleave(athLeaveReq);
    return ApiRestResponse.success();
    }
//学习记录小程序的个人旷课和请假
    @GetMapping("/v2/truant")
    public ApiRestResponse truant(String mobile,Integer leave,Integer pageNum, Integer pageSize){
        PageInfo truant = athLeaveService.truant(mobile, leave, pageNum, pageSize);
        return ApiRestResponse.success(truant);
    }
}
